home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / sbin / update-default-ispell < prev    next >
Encoding:
Text File  |  2011-01-12  |  6.7 KB  |  220 lines

  1. #!/usr/bin/perl -w
  2.  
  3. use Debian::DictionariesCommon q(:all);
  4. use Debconf::Client::ConfModule q(:all);
  5. use Getopt::Long;
  6.  
  7. dico_checkroot ();
  8.  
  9. my $rebuild = '';
  10. my $ignoresymlinks = '';
  11.  
  12. GetOptions ('rebuild'         => \$rebuild,
  13.         'ignore-symlinks' => \$ignoresymlinks);
  14.  
  15. version ('2.0');
  16.  
  17. my $class     = "ispell";
  18. my $libdir    = "/usr/lib/ispell";
  19. my $question  = "dictionaries-common/default-$class";
  20. my $iquestion = "dictionaries-common/invalid_debconf_value";
  21. my $linkdir   = "/etc/dictionaries-common";
  22. my $manual    = '';
  23. my $program   = "update-default-$class";
  24. my $debug     = 1 if exists $ENV{'DICT_COMMON_DEBUG'};
  25. my $newflag   = "/var/cache/dictionaries-common/flag-$class-new";
  26. # -- Ispell only stuff
  27. my $emacsen_default      = "nil";
  28. my $cache_dir            = "/var/cache/dictionaries-common";
  29. my $emacsen_default_file = "$cache_dir/emacsen-ispell-default.el";
  30. my $ispell_dicts_list    = "$cache_dir/ispell-dicts-list.txt";
  31. # -- End of ispell only stuff
  32.  
  33. # This flag is intended for remove-default-$class. If we are here we do not
  34. # need it any longer, so we reset for future apt runs by cleaning it.
  35. if ( -f $newflag ){
  36.   print STDERR "$program: Removing $newflag\n" if $debug;
  37.   unlink $newflag
  38.     or print STDERR " $program: Warning: could not remove $newflag\n";
  39. }
  40.  
  41. ($ret, $value)  = get ($question);
  42.  
  43. if ($ret == 0 && $value ){
  44.   updatedb ($class);
  45.   my $dictionaries = loaddb ($class);
  46.  
  47.   # Check if we are in manual mode
  48.   if ( $value =~ m/^Manual.*/i ){
  49.     $ignoresymlinks = "yes";
  50.     $manual         = "yes";
  51.   } else {
  52.     unless( %$dictionaries ) {
  53.       # Unset value unless Manual or class elements available
  54.       print STDERR "$program: No Manual mode and no $class elements. $question unset.\n" if $debug;
  55.       $value = "";
  56.       set($question,$value);
  57.       go();
  58.       $ignoresymlinks = "yes";
  59.       $manual         = "yes";
  60.     }
  61.   }
  62.  
  63.   if ( not $ignoresymlinks ) {
  64.  
  65.     # Handle invalid debconf values
  66.     if ( not exists $dictionaries->{$value} ){
  67.       my @available_keys = ();
  68.       foreach ( split (/\s*,\s*/, metaget ($question, "choices")) ){
  69.     # strip leading/trailing whitespace and create a list of available keys
  70.     s/^\s+//;
  71.     s/\s+$//;
  72.     push (@available_keys,$_) if ( exists $dictionaries->{$_} );
  73.       }
  74.       my $choices    = join (', ', sort {lc $a cmp lc $b} @available_keys);
  75.       my $forced_key = $available_keys[0] ||
  76.     die "Selected ispell dictionary:\n" .
  77.     " $value \n" .
  78.     "does not correspond to any installed package in the system\n" .
  79.     "and no alternative ispell dictionary could be selected.\n";
  80.       subst($iquestion,"value",$value);
  81.       fset ($iquestion,"seen","false");
  82.       input("high",$iquestion);                # Warn about what happened
  83.       subst ($question, "choices", $choices);  # Put sane values in debconf choices field
  84.       subst ($question, "echoices", $choices); # Put sane values in debconf echoices field
  85.       set ($question, $forced_key);            # Set debconf value to a sane one
  86.       fset ($question,"seen","false");
  87.       input ("critical", $question);
  88.       title ("dictionaries-common: ispell dictionaries");
  89.       go ();
  90.       ($ret, $value) = get ($question);
  91.       die "\n Could not get a valid value for debconf question:\n" .
  92.     "$question\n"
  93.     if ( $ret != 0 ); # This should never be reached
  94.     }
  95.  
  96.     # Check if links are possible and complain otherwise
  97.     if ( exists $dictionaries->{$value}{"hash-name"} ){
  98.       my $hash   = "$libdir/" . $dictionaries->{$value}{"hash-name"};
  99.       foreach my $i (".hash", ".aff") {
  100.     if (-e "$hash$i") {
  101.       system "ln -fs $hash$i $linkdir/default$i";
  102.     } else {
  103.       die "
  104. When trying to make the default link to a ispell dictionary
  105. the file to link [$hash$i] was not found. Please report this as a bug to the
  106. maintainer of the ispell dictionary package you tried to
  107. select.
  108. In the meantime select other default value for your ispell dictionary.\n";
  109.     }
  110.       }
  111.     } else {
  112.       die "Selected ispell dictionary:\n" .
  113.     " $value \n" .
  114.     "does not contain a hash name entry in the database.\n";
  115.     }
  116.   }
  117.  
  118. # This here is only for ispell, not wordlist
  119.   if ( $manual ){
  120.     dico_setsysdefault ($class,"");
  121.   } else {
  122.     dico_setsysdefault ($class,$value);
  123.   }
  124.  
  125.   # Printing a plain list with installed ispell dictionaries,
  126.   open (IDICTS,"> $ispell_dicts_list") ||
  127.     die "Could not open $ispell_dicts_list for writing\n";
  128.   print IDICTS ""; # Make sure this is void if no dictionaries available.
  129.   foreach ( sort keys %{$dictionaries} ){
  130.     print IDICTS "$_\n";
  131.   }
  132.   close (IDICTS);
  133.  
  134.   # Write ispell default dict for emacsen
  135.   unless ( $manual ){
  136.     if ( exists $dictionaries->{$value}{"emacs-display"}
  137.      and lc($dictionaries->{$value}{"emacs-display"}) eq "no" ){
  138.       $emacsen_default = "nil";
  139.     } elsif ( exists $dictionaries->{$value}{"emacsen-name"} ){
  140.       $emacsen_default = "\"" . $dictionaries->{$value}{"emacsen-name"} . "\"";
  141.     } elsif( exists $dictionaries->{$value}{"hash-name"} ){
  142.       $emacsen_default = "\"" . $dictionaries->{$value}{"hash-name"} . "\"";
  143.     }
  144.   }
  145.   #
  146. }
  147.  
  148. # Printing the default ispell dictionary under emacs
  149. open (EMISDEFAULT,"> $emacsen_default_file");
  150. print EMISDEFAULT ";; File automatically generated by update-default-ispell
  151. ;;
  152. ;; Do not manually edit!! Use select-default-ispell script instead
  153.  
  154. (set-variable \'debian-ispell-dictionary $emacsen_default)\n";
  155. close EMISDEFAULT;
  156.  
  157.  
  158. if ($rebuild) {
  159.  
  160.   updatedb ($class);
  161.  
  162.   # Ispell emacsen + jed support
  163.   build_emacsen_support ();
  164.   build_jed_support ();
  165.   build_squirrelmail_support ();
  166.   system ("ispell-autobuildhash") == 0
  167.       or die "Error running ispell-autobuildhash\n";
  168.   # End of specific ispell support 
  169. }
  170.  
  171. # Local Variables:
  172. #  perl-indent-level: 2
  173. # End:
  174.  
  175. __END__
  176.  
  177. =head1 NAME
  178.  
  179. update-default-ispell - update default ispell dictionary
  180.  
  181. =head1 SYNOPSIS
  182.  
  183.  update-default-ispell [--rebuild] [--ignore-symlinks]
  184.  
  185. =head1 DESCRIPTION
  186.  
  187. WARNING: Not to be used from the command line unless you know very well what you are doing.
  188.  
  189. This program is intended to be called from package postinst
  190. (with B<--rebuild>), from B<select-default-ispell> or
  191. from dictionaries-common
  192. postinst (with B<--ignore-symlinks>).
  193.  
  194. Reads the system default from the debconf database and set default links in
  195. F</etc/dictionaries-common> pointing to the appropriate files in
  196. F</usr/lib/ispell/>.  Also
  197. updates the system-wide setting F</etc/dictionaries-common/ispell-default>.
  198. If option B<--rebuild> is given, rebuilds the
  199. F</var/cache/dictionaries-common/ispell.db> 
  200. and the emacsen, jed, and SquirrelMail support (to be put in
  201. F</var/cache/dictionaries-common/>) from the files in
  202. F</var/lib/dictionaries-common/ispell>
  203.  
  204.  
  205. =head1 OPTIONS
  206.  
  207. --rebuild          Rebuild database, emacsen and jed stuff
  208. --ignore-symlinks  Do not set symlinks
  209.  
  210.  
  211. =head1 SEE ALSO
  212.  
  213. The dictionaries-common policy document
  214.  
  215. =head1 AUTHORS
  216.  
  217. Rafael Laboissiere
  218.  
  219. =cut
  220.